#!/usr/bin/env python
from lib.format_time import *
from lib.HandleMysql import *
from lib.switch_code import *
import sys
import re
reload(sys)
sys.setdefaultencoding('utf-8')


#mysql - groupbuy
def set_gb_conn():    
    conn = HandleMysql('groupbuyv2-s.db.58dns.org','58885','gupbuyuser_rdon',"ks*&dke12(*aws0",'dbwww58com_groupbuy_v2')
    conn.connect()
    return conn

#mysql - stats
def set_open_conn():    
    conn = HandleMysql('10.3.12.14','58885','ec_stat','L#c8UM5RGh5C','dbwww58com_groupbuy_open')
    conn.connect()
    return conn

def main():
    conn_op = set_open_conn()
    query_op = "truncate table cityinfo;"
    conn_op.execute_sql(query_op)
    
    conn = set_gb_conn()  
    query = "select id,cityname,rank from cityinfo"
    items = conn.get_results(query)
    for item in items:
        p_id = item[0]
        p_name = item[1]
        p_rank = item[2]
        
        param = [p_id,p_name,p_rank]
        stat_table = "cityinfo"  
        conn_op.insert_record(stat_table,param)
    
if __name__=='__main__':
    main()